package com.ai.aicontact.execmgn.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ai.aicontact.busi.entity.ExecInstruction;
import com.ai.aicontact.busi.entity.RedBlackList;
import com.ai.aicontact.busi.service.RedBlackListService;
import com.ai.aicontact.common.vo.Grid;
import com.ai.aicontact.common.vo.Json;
import com.ai.aicontact.common.vo.PageFilter;

@Controller
@RequestMapping("/contactmgn/redblack")
public class RedBlackListController {
	
	@RequestMapping("/{jspname}")
	public String web(@PathVariable("jspname") String jspname) {
		return "/contactmgn/redblack/" + jspname;
	}
	
	@Autowired
	private RedBlackListService redBlackListService;
	
	
	@ResponseBody
	@RequestMapping("queryRedBlackList")
	public Grid queryRedBlackList(String keyWord,RedBlackList redBlackList,PageFilter pf) throws Exception {
		Grid grid = new Grid();
		List<RedBlackList> rows = redBlackListService.queryRedBlackList(keyWord,redBlackList, pf);
		Long total = redBlackListService.countRedBlackList(keyWord, redBlackList);
		grid.setRows(rows);
		grid.setTotal(total);
		return grid;
	}
	
	
	@ResponseBody
	@RequestMapping("saveRedBlackList")
	public Json saveRedBlackList(RedBlackList redBlackList) throws Exception {
		Json json = new Json();
		try {
			redBlackListService.saveRedAndBlackList(redBlackList);
			json.setObj(redBlackList);
			json.setSuccess(true);
			json.setMsg("保存成功");
		} catch (Exception e) {
			json.setMsg(e.getMessage());
		}
		return json;
	}

	
	@ResponseBody
	@RequestMapping("delRedBlackList")
	public Json delRedBlackList(RedBlackList redBlackList) throws Exception {
		Json json = new Json();
		try {
			redBlackListService.deleteRedBlackList(redBlackList);
			json.setSuccess(true);
			json.setMsg("删除成功");
		} catch (Exception e) {
			json.setMsg(e.getMessage());
		}
		return json;
	}

}
